package com.fenghongzhang.day004;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

/**
 *
 */
public class MainActivity extends AppCompatActivity {

    private OneFragment oneFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        oneFragment = new OneFragment();
//        OneFragment oneFragment1 = new OneFragment();
        //fragment管理者 -> 增加, 删除, 替换. 隐藏,显示.
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        //开启一个事务
        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
        //添加
        fragmentTransaction.add(R.id.ll,oneFragment);
        //添加到回退站
        fragmentTransaction.addToBackStack("123");

        //删除
//        fragmentTransaction.remove(oneFragment);
        //替换
//        fragmentTransaction.replace(R.id.ll,new BlankFragment());
        //隐藏
//        fragmentTransaction.hide(oneFragment);
        //显示
//        fragmentTransaction.show(oneFragment);
        //提交事务
        fragmentTransaction.commit();

    }

    public void remove(View view) {
        FragmentManager supportFragmentManager = getSupportFragmentManager();

        //调用弹出栈
        supportFragmentManager.popBackStack();

        //开启一个事务
//        FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
        //删除
//        fragmentTransaction.remove(oneFragment);
//        fragmentTransaction.commit();

    }


}
